<template name="goodsLists">
	<view class="content">
		<uv-search v-model="searchValue" @search="search" @custom="search" bgColor="white" :showAction="true"
			actionText="搜索" :animation="true"></uv-search>
		<goodsList ref="goodsListRef" :defaultRequest="false" />
	</view>
</template>

<script setup>
	import {
		ref,
		getCurrentInstance,
		nextTick
	} from "vue";
	import {
		onLoad,
		onReachBottom,
		onReady,
	} from '@dcloudio/uni-app'
	const app = getApp()
	const {
		proxy,
		ctx
	} = getCurrentInstance()
	const goodsListRef = ref(null)
	const searchValue = ref("")
	const searchData = ref({})
	const search = () => {
		searchData.value = {
			name: searchValue.value || ""
		}
		app.vibrate()
		goodsListRef.value.search(searchData.value)
	};
	onLoad((e) => {
		searchData.value = e
	})
	onReady(() => {
		const eventChannel = proxy.getOpenerEventChannel();
		// 监听事件，获取上一页面通过eventChannel传送到当前页面的数据
		eventChannel.on('setsearchValue', (value) => {
			searchValue.value = value || ""
			goodsListRef.value.getData(searchData.value)
		})
	})
	onReachBottom(() => {
		app.vibrate()
		goodsListRef.value.getData(searchData.value)
	})
</script>

<style lang="scss" scoped>
	.content {
		padding: 10px;
		display: flex;
		flex-direction: column;
		gap: 10px;
	}
</style>